package com.itboye.textileexpes.adapter;

import java.util.ArrayList;
import java.util.List;

import com.itboye.textileexpes.beans.KefuBeans;
import com.itboye.textileexpes.beans.NewsKefuBeans;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.R.layout;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class KefuAdapter extends BaseExpandableListAdapter {
	private List<NewsKefuBeans> group;
	// private List<List<NewsKefuBeans>> list;
	private Context context;

	public KefuAdapter(List<NewsKefuBeans> grop, Context context) {
		// TODO Auto-generated constructor stub
		this.group = grop;
		// this.list = list;
		this.context = context;
	}

	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return group == null ? 0 : group.size();
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
		return group.size();
	}

	@Override
	public Object getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		return group.get(groupPosition);
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return group.get(groupPosition).getList().get(childPosition);
	}

	@Override
	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return groupPosition;
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return childPosition;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	/**
	 * 显示：group
	 */
	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_exlsit, null);
			holder = new ViewHolder();
			holder.textView = (TextView) convertView
					.findViewById(R.id.textView1);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.textView.setText(group.get(groupPosition).getGroup_name());
		holder.textView.setTextSize(25);
		holder.textView.setPadding(36, 10, 0, 10);
		return convertView;

	}

	/**
	 * 显示：child
	 */
	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_curstomer, null);
			holder.textView = (TextView) convertView
					.findViewById(R.id.customer_name);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		// System.out.println(">>>>>>>>>>>>>>>>>"+group.get(groupPosition).getList().get(childPosition).getNickname());
		holder.textView.setText(group.get(groupPosition).getList()
				.get(childPosition).getNickname());
		holder.textView.setTextSize(20);
		// holder.textView.setPadding(72, 10, 0, 10);
		return convertView;
	}

	class ViewHolder {
		TextView textView;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return true;
	}
}
